﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace MDMAPI.Filter
{
    public class LogFilterAttribute: ActionFilterAttribute
    {
  
        private log4net.ILog log = LogManager.GetLogger("");
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var message = new StringBuilder();
            message.Append(string.Format("调用的接口是 :controller {0}, action :{1}",
              filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
              filterContext.ActionDescriptor.ActionName));
            log.Debug(message);
        }
      //  对每个请求的error做处理，这个需要重写OnActionExecuted
       public override void OnActionExecuted(HttpActionExecutedContext filterContext)
        {
            if (filterContext.Exception == null)
            {
                return;
            }
            else
            {
                Exception ex = filterContext.Exception;
                log.Error(ex);
            }
        }
    }
}